<?php 
error_reporting(E_ALL);
ini_set("display_errors", "On");
header('Content-Type: text/html; charset=UTF-8');
require 'class_mysql.php';
$c['host'] = '127.0.0.1';
$c['username'] = 'root';
$c['password'] = '123456';
$c['dbname'] = 'lvzhiwo';
$c['charset'] = 'utf8'; 
$db = new Mysql($c);


function explode_attributes($attributes_name){
	$attributes = $db->find("SELECT * FROM  `ecs_attribute` WHERE attr_name LIKE '%$attributes_name %'");
	
	foreach ($attributes as $attribute){
		$res = $db->find("SELECT * FROM  `ecs_goods_attr` WHERE attr_id = {$attribute->attr_id}");
		foreach ($res as $one){
			
			$one->attr_value = str_ireplace('&nbsp;', '_', $one->attr_value);
			$one->attr_value = mb_convert_encoding ($one->attr_value, "UTF-8", "HTML-ENTITIES");
			$atts = (explode('_', $one->attr_value));
			
			//print_r($atts);
			//print_r($one->goods_id);
			
			$sql = "DELETE FROM `ecs_goods_attr` WHERE goods_attr_id = {$one->goods_attr_id}";
			$db->query($sql);
			
			foreach ($atts as $att){
				if($att != ''){
					$sql = "INSERT INTO `ecs_goods_attr`(goods_attr_id,	goods_id, attr_id, attr_value)
					VALUES (NULL ,  {$one->goods_id},  {$one->attr_id},  '$att')";
					$db->query($sql);
				}
			}
			
			 
		}
	}
}

/* 
				
$sql = "INSERT INTO `ecs_goods_attr`(goods_attr_id,	goods_id, attr_id, attr_value)
		VALUES (NULL ,  $good_id,  $attr_id,  '$v')
		";
$db->query($sql);
 */